<html>
<head><meta charset="utf-8"><title>module files · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html">module files</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209836440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209836440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209836440">(Sep 11 2020 at 21:19)</a>:</h4>
<p>Is the convention to have <code>mymodule/{mod, foo, bar}.rs</code> or <code>mymodule.rs</code> and <code>mymodule/{foo, bar}.rs</code>?</p>



<a name="209836536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209836536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209836536">(Sep 11 2020 at 21:20)</a>:</h4>
<p>I usually go for the latter in new code</p>



<a name="209836748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209836748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209836748">(Sep 11 2020 at 21:22)</a>:</h4>
<p>Huh, that's interesting. I thought that was the older version!</p>



<a name="209836837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209836837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209836837">(Sep 11 2020 at 21:23)</a>:</h4>
<p>new as of 2018 Edition: <a href="https://doc.rust-lang.org/nightly/edition-guide/rust-2018/module-system/path-clarity.html">https://doc.rust-lang.org/nightly/edition-guide/rust-2018/module-system/path-clarity.html</a></p>



<a name="209837179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209837179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209837179">(Sep 11 2020 at 21:27)</a>:</h4>
<p>Yup. Formerly, you couldn't have <code>mymodule.rs</code> if you also had <code>mymodule/*.rs</code>, but 2018 added that.</p>



<a name="209837214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209837214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209837214">(Sep 11 2020 at 21:27)</a>:</h4>
<p>In Rust 2015, you <em>had</em> to rename <code>mymodule.rs</code> to <code>mymodule/mod.rs</code> if you wanted to add submodules.</p>



<a name="209837471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209837471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209837471">(Sep 11 2020 at 21:30)</a>:</h4>
<p>Is there a convention, or is it just a personal choice?</p>



<a name="209837516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209837516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209837516">(Sep 11 2020 at 21:30)</a>:</h4>
<p>There is no lint for this, therefore: Personal choice</p>



<a name="209838182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209838182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209838182">(Sep 11 2020 at 21:36)</a>:</h4>
<p>I like the "new" way so it means that in a level, the main module name in question _always_ exists as <code>name.rs</code>, and is not at <code>name/mod.rs</code>, but some people like it the other way around because it means a module is always complete in a folder.</p>



<a name="209838609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209838609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209838609">(Sep 11 2020 at 21:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/122651-general/topic/module.20files/near/209837471">said</a>:</p>
<blockquote>
<p>Is there a convention, or is it just a personal choice?</p>
</blockquote>
<p>There's no convention. When we created the Rust 2018 module system and made that an option, we hoped that people would tend to use it, but we didn't want any kind of deprecation that would annoy people who used or preferred the old way.</p>



<a name="209838774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209838774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209838774">(Sep 11 2020 at 21:42)</a>:</h4>
<p>Yeah, I learned Rust this year, but I prefer the old way because of the reason <code>@Jubilee</code> mentioned :)</p>



<a name="209839495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209839495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209839495">(Sep 11 2020 at 21:50)</a>:</h4>
<p>imo this should totally be a warning</p>



<a name="209875417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209875417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209875417">(Sep 12 2020 at 10:36)</a>:</h4>
<p>I really hope the new way can work together with <code>#[path="xxx.rs"]</code>... This will be a language change though.</p>



<a name="209877779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209877779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209877779">(Sep 12 2020 at 11:44)</a>:</h4>
<p>I'm not sure what you mean, I think it does?</p>



<a name="209883598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209883598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209883598">(Sep 12 2020 at 14:26)</a>:</h4>
<p>good news!</p>
<p>with inline modules, you don't need <a href="http://foo.rs">foo.rs</a> next to foo/ <em>or</em> <a href="http://mod.rs">mod.rs</a> within foo/</p>
<div class="codehilite"><pre><span></span><code><span class="c1">// maps to folder foo/</span>
<span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="c1">// maps to foo/bar.rs</span>
<span class="w">  </span><span class="k">mod</span> <span class="nn">bar</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="209887429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209887429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209887429">(Sep 12 2020 at 16:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/module.20files/near/209877779">said</a>:</p>
<blockquote>
<p>I'm not sure what you mean, I think it does?</p>
</blockquote>
<p>When <code>#[path="xxx.rs"]</code> is specified, it always acts as if <code>xxx.rs</code> is <code>mod.rs</code>, and assumes its child module is in the same directory level instead of under <code>xxx/</code></p>



<a name="209888074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209888074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209888074">(Sep 12 2020 at 16:11)</a>:</h4>
<p>That is surprising to me</p>



<a name="209894041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209894041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209894041">(Sep 12 2020 at 18:32)</a>:</h4>
<p>I remember seeing that a little while ago too. That seems like a bug, though it might be a difficult one to fix compatibly.</p>



<a name="209895712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209895712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209895712">(Sep 12 2020 at 19:16)</a>:</h4>
<p>The new way can make file name based search easier and creates less  noise in git when adding the first/removing the last submodule which is why I started using it for new projects. But it's preference only. The part about the path attribute not working seems like a bug, I guess the code behind it just wasn't updated but I might be wrong.</p>



<a name="209898540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209898540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209898540">(Sep 12 2020 at 20:29)</a>:</h4>
<p>The <code>#[path]</code> behavior is more or less intentional. Its behavior was <a href="https://github.com/rust-lang/rust/pull/55108#issuecomment-430107039">discovered</a> just before the 2018 edition was to be released.  Because <code>#[path]</code> had a specific behavior since 1.0, it wasn't feasible to change it in time. One problem is that interpreting it differently would require a tool like <code>rustfix</code> to be able to rename files, which it can't (assuming almost all changes should be rustfix-able).  Finishing the documentation for this has been on my todo list for over a year. <span aria-label="frown" class="emoji emoji-1f641" role="img" title="frown">:frown:</span></p>



<a name="209900328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209900328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209900328">(Sep 12 2020 at 21:14)</a>:</h4>
<p>aha, that does bring memories back, okay.</p>



<a name="209904599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209904599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209904599">(Sep 12 2020 at 23:30)</a>:</h4>
<p>could it go on the 2021 list, or later edition?</p>



<a name="209905182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209905182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209905182">(Sep 12 2020 at 23:46)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> as an unfixable lint? I'm pretty hesitant to have file renames, but maybe that's a false fear</p>



<a name="209905261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209905261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209905261">(Sep 12 2020 at 23:49)</a>:</h4>
<p>if <code>cargo fix</code> (or whatever it's called) performs arbitrary changes on the <em>content</em> of files, there's really no moral difference in renaming files too.</p>



<a name="209906700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/module%20files/near/209906700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/module.20files.html#209906700">(Sep 13 2020 at 00:31)</a>:</h4>
<p>I think it's fine to keep default <code>#[path]</code> working the current way, but i wish there could be an argument that specifies that its submodules are in a subdirectory(2018 style) instead of same directory level (2015 style)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>